<?php
/**
 * Created by PhpStorm.
 * User: Sky
 * Date: 16/1/25
 * Time: 下午2:47
 */

use yii\helpers\Html;
use yii\helpers\Url;
use app\lib\WeixinUtils;

/* @var $this yii\web\View */
/* @var $content string 字符串 */


$web = Url::to("@web");
?>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta content="telephone=no" name="format-detection" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>领取的礼物</title>
    <link href="<?= $web ?>/css/global.css" rel="stylesheet" />
    <link href="<?= $web ?>/css/bag/gift-receive-detail.css" rel="stylesheet" />
    <script src="<?= $web ?>/js/jquery.js"></script>
    <script src="<?= $web ?>/js/tools.js"></script>
    <meta charset="utf-8" />

    <script type="text/javascript">
        $(function ()
        {
            // 任何需要执行的js特效
            var w = $(document).width();
            if (w > 640)
            {
                w = 640;
            }
            $("body").css("font-size", w * 20 / 320);
            if(GOODS_CL_flag==0){
                $('.btn-exchange').click(function(){
                    window.location.href = "<?=Url::to(["wx-bag/collect-goods-message"]);?>?code=" + '<?=$bagInfo['CODE']?>';
                });
            }

            if(GOODS_CL_flag==1){//龙珠
                $('.btn-exchange').hide();
                $('.gift-desc span').text("别急！龙珠成套方可兑换，龙珠大奖等着你！");
            }
            if(GOODS_CL_flag==2){//兑换码
                $('.btn-exchange').html('领取兑换码');
                $('.btn-exchange').click(function(){
                    exchange_Ticket();
                });
            }
            if(GOODS_CL_flag==3){//兑换朵拉币
                $('.btn-exchange').html('兑换朵拉币');
                $('.btn-exchange').click(function(){
                    exchange_coin();
                });
            }
        });
        var GOODS_CL_flag="<?=$GOODS_CL_flag?>";

        //兑换朵拉币
        function exchange_coin(){
            if(confirm('您想把此礼品兑换成{0}个朵拉币吗?'._format(<?=$goods["PRICE_G"]?>))){
                var data={};
                data.type_id=2;
                data.order_id="<?=$code?>";
                data.exchange_id="<?=$goods['CODE_ID']?>";

                var re=returnjson("<?=Url::to(["wx-home/receive-dora-coin-handle"])?>",data);
                if(re.flag==1){
                    alert('兑换成功!');
                    window.location.href = "<?=Url::to(["wx-bag/view-gift-nav"]);?>?code_id=" + "<?=$goods['CODE_ID']?>";
                }else{
                    alert(re.msg);
                    return false;
                }
            }
        }
        //获取兑换码
        function exchange_Ticket(){
            var data={};

            data.code_id="<?=$goods['CODE_ID']?>";

            var re=returnjson("<?=Url::to(["wx-bag/submit-order-ticket-handle"])?>",data);
            if(re.flag==1){
                alert('兑换成功!');
                window.location.href = "<?=Url::to(["wx-bag/view-gift-nav"]);?>?code_id=" + "<?=$goods['CODE_ID']?>";
            }else{
                alert(re.msg);
                return false;
            }
        }
        function href_goods_detail(goods_code) {
            goods_code = encodeURI(goods_code);
            window.location.href = "<?=Url::to(["wx-bag/goods-detail"]);?>?goods_code=" + goods_code;
        }
    </script>
</head>
<body>
<div class="main">
    <div class="gift-container">
        <div class="title-container">
            <div class="title-content">
                <div class="logo">  </div>
                <div class="logo-text"> </div>
                <div class="title">
                    <table cellspacing="0" cellpadding="0">
                        <tr>
                            <td id="title-main" style="width: 17em; overflow: hidden; font-size: 0.6em;"><?php
                                $bag_name= $bagInfo['BAG_NAME'];
                                $nick_name= $bagInfo['NICK_NAME'];

                                if($bag_name==""){

                                    echo "来自{$nick_name}的朵拉礼包";
                                }else{
                                    echo $bagInfo['BAG_NAME'];
                                }


                                ?></td>
                        </tr>
                        <tr>
                            <td id="title-desc">有效期：永久</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="bless-container">
                <div class="user-head">
                    <img src="<?= $bagInfo['HEADER_URL'] ?>" />
                </div>
                <div class="user-bless">
                    <table cellpadding="0" cellspacing="0">
                        <tr>
                            <td id="user-target"><?=$bagInfo['NICK_NAME']?>：</td>
                        </tr>
                        <tr>
                            <td id="bless-text"><?=$bagInfo['BLESSING']?></td>
                        </tr>
                    </table>
                </div>
            </div>

        </div>
    </div>
    <div class="gift-img" onclick="href_goods_detail('<?=$goods['GOODS_CODE']?>')">
        <img src="<?=$goods['GOODS_IMG_URL']?>" />
    </div>
    <div class="gift-name" onclick="href_goods_detail('<?=$goods['GOODS_CODE']?>')">
        <span><?=$goods['GOODS_NAME']?></span>
    </div>
    <div class="gift-desc">
        <span>您的商品还未兑换，快去兑换吧 </span>
    </div>
    <div class="btn-exchange">立即兑换</div>
</div>
</body>
</html>
